﻿SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 ;
USE `mydb` ;

-- -----------------------------------------------------
-- Table `mydb`.`admin`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`admin` (
  `idAdmin` INT(11) NOT NULL AUTO_INCREMENT ,
  `Nombre` VARCHAR(45) NULL DEFAULT NULL ,
  `Access` INT(11) NULL DEFAULT NULL ,
  PRIMARY KEY (`idAdmin`) )
ENGINE = InnoDB
AUTO_INCREMENT = 119
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `mydb`.`bans`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`bans` (
  `idBans` INT(11) NOT NULL AUTO_INCREMENT ,
  `Nombre` VARCHAR(45) NULL DEFAULT NULL ,
  `FechaExpiracion` DATETIME NULL DEFAULT NULL ,
  `Admin_idAdmin` INT(11) NULL DEFAULT NULL ,
  `Expirado` TINYINT(1) NULL DEFAULT '0' ,
  PRIMARY KEY (`idBans`) ,
  INDEX `fk_Bans_Admin` (`Admin_idAdmin` ASC) ,
  INDEX `asd` (`Admin_idAdmin` ASC) ,
  CONSTRAINT `asd`
    FOREIGN KEY (`Admin_idAdmin` )
    REFERENCES `mydb`.`admin` (`idAdmin` )
    ON DELETE SET NULL
    ON UPDATE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 214
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `mydb`.`game`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`game` (
  `idGame` INT(11) NOT NULL AUTO_INCREMENT ,
  `Fecha` VARCHAR(45) NULL DEFAULT NULL ,
  `Resultado` ENUM('sentinel','scourge','draw') NULL DEFAULT NULL ,
  `AdminChange` TINYINT(4) NULL DEFAULT '0' ,
  `admin` INT(11) NULL DEFAULT NULL ,
  PRIMARY KEY (`idGame`) ,
  INDEX `admin_game_change` (`admin` ASC) ,
  CONSTRAINT `admin_game_change`
    FOREIGN KEY (`admin` )
    REFERENCES `mydb`.`admin` (`idAdmin` )
    ON DELETE SET NULL
    ON UPDATE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 148144380
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `mydb`.`vouch`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`vouch` (
  `idvouch` INT(11) NOT NULL AUTO_INCREMENT ,
  `Nombre` VARCHAR(45) NULL DEFAULT NULL ,
  `Voucher` INT(11) NOT NULL ,
  `Exp` DOUBLE NULL DEFAULT '1000' ,
  `Streak` INT(11) NULL DEFAULT '0' ,
  `Confianza` DOUBLE NULL DEFAULT '50' ,
  `Traunt` INT(11) NULL DEFAULT '0' ,
  PRIMARY KEY (`idvouch`) ,
  INDEX `fk_vouch_admin1` (`Voucher` ASC) ,
  CONSTRAINT `fk_vouch_admin1`
    FOREIGN KEY (`Voucher` )
    REFERENCES `mydb`.`admin` (`idAdmin` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
AUTO_INCREMENT = 592
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `mydb`.`vouch_has_exclude`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`vouch_has_exclude` (
  `vouch_idvouch` INT(11) NOT NULL ,
  `game_idGame` INT(11) NOT NULL ,
  PRIMARY KEY (`vouch_idvouch`, `game_idGame`) ,
  INDEX `fk_vouch_has_game1_game1` (`game_idGame` ASC) ,
  INDEX `fk_vouch_has_game1_vouch1` (`vouch_idvouch` ASC) ,
  CONSTRAINT `fk_vouch_has_game1_game1`
    FOREIGN KEY (`game_idGame` )
    REFERENCES `mydb`.`game` (`idGame` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_vouch_has_game1_vouch1`
    FOREIGN KEY (`vouch_idvouch` )
    REFERENCES `mydb`.`vouch` (`idvouch` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `mydb`.`vouch_excluder`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`vouch_excluder` (
  `excluder` INT(11) NOT NULL ,
  `excluded` INT(11) NOT NULL ,
  `excluded_game_idGame` INT(11) NOT NULL ,
  PRIMARY KEY (`excluder`, `excluded`, `excluded_game_idGame`) ,
  INDEX `fk_vouch_has_vouch_has_exclude_vouch_has_exclude1` (`excluded` ASC, `excluded_game_idGame` ASC) ,
  INDEX `fk_vouch_has_vouch_has_exclude_vouch1` (`excluder` ASC) ,
  CONSTRAINT `fk_vouch_has_vouch_has_exclude_vouch1`
    FOREIGN KEY (`excluder` )
    REFERENCES `mydb`.`vouch` (`idvouch` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_vouch_has_vouch_has_exclude_vouch_has_exclude1`
    FOREIGN KEY (`excluded` , `excluded_game_idGame` )
    REFERENCES `mydb`.`vouch_has_exclude` (`vouch_idvouch` , `game_idGame` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `mydb`.`vouch_has_traunt`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`vouch_has_traunt` (
  `vouch_idvouch` INT(11) NOT NULL ,
  `game_idGame` INT(11) NOT NULL ,
  PRIMARY KEY (`vouch_idvouch`, `game_idGame`) ,
  INDEX `fk_vouch_has_game_game1` (`game_idGame` ASC) ,
  INDEX `fk_vouch_has_game_vouch1` (`vouch_idvouch` ASC) ,
  CONSTRAINT `fk_vouch_has_game_game12`
    FOREIGN KEY (`game_idGame` )
    REFERENCES `mydb`.`game` (`idGame` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_vouch_has_game_vouch12`
    FOREIGN KEY (`vouch_idvouch` )
    REFERENCES `mydb`.`vouch` (`idvouch` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `mydb`.`vouch_plays_game`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`vouch_plays_game` (
  `Vouch_idvouch` INT(11) NOT NULL ,
  `Game_idGame` INT(11) NOT NULL ,
  `team` INT(11) NULL DEFAULT NULL ,
  `Result` DOUBLE NULL DEFAULT NULL ,
  `Streak` INT(11) NULL DEFAULT NULL ,
  PRIMARY KEY (`Vouch_idvouch`, `Game_idGame`) ,
  INDEX `fk_Vouch_has_Game_Game1` (`Game_idGame` ASC) ,
  CONSTRAINT `fk_Vouch_has_Game_Game1`
    FOREIGN KEY (`Game_idGame` )
    REFERENCES `mydb`.`game` (`idGame` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_Vouch_has_Game_Game2`
    FOREIGN KEY (`Game_idGame` )
    REFERENCES `mydb`.`game` (`idGame` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_Vouch_has_Game_Vouch`
    FOREIGN KEY (`Vouch_idvouch` )
    REFERENCES `mydb`.`vouch` (`idvouch` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_Vouch_has_Game_Vouch2`
    FOREIGN KEY (`Vouch_idvouch` )
    REFERENCES `mydb`.`vouch` (`idvouch` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `vouch_plays_game_ibfk_1`
    FOREIGN KEY (`Game_idGame` )
    REFERENCES `mydb`.`game` (`idGame` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `vouch_plays_game_ibfk_2`
    FOREIGN KEY (`Vouch_idvouch` )
    REFERENCES `mydb`.`vouch` (`idvouch` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `vouch_plays_game_ibfk_3`
    FOREIGN KEY (`Game_idGame` )
    REFERENCES `mydb`.`game` (`idGame` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `vouch_plays_game_ibfk_4`
    FOREIGN KEY (`Vouch_idvouch` )
    REFERENCES `mydb`.`vouch` (`idvouch` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `vouch_plays_game_ibfk_5`
    FOREIGN KEY (`Game_idGame` )
    REFERENCES `mydb`.`game` (`idGame` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `vouch_plays_game_ibfk_6`
    FOREIGN KEY (`Vouch_idvouch` )
    REFERENCES `mydb`.`vouch` (`idvouch` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;


-- -----------------------------------------------------
-- Table `mydb`.`vouch_traunter`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `mydb`.`vouch_traunter` (
  `traunter` INT(11) NOT NULL ,
  `traunted` INT(11) NOT NULL ,
  `traunted_game_idGame` INT(11) NOT NULL ,
  PRIMARY KEY (`traunter`, `traunted`, `traunted_game_idGame`) ,
  INDEX `fk_vouch_has_vouch_has_traunt_vouch_has_traunt1` (`traunted` ASC, `traunted_game_idGame` ASC) ,
  INDEX `fk_vouch_has_vouch_has_traunt_vouch1` (`traunter` ASC) ,
  CONSTRAINT `fk_vouch_has_vouch_has_traunt_vouch1`
    FOREIGN KEY (`traunter` )
    REFERENCES `mydb`.`vouch` (`idvouch` )
    ON DELETE CASCADE
    ON UPDATE CASCADE,
  CONSTRAINT `fk_vouch_has_vouch_has_traunt_vouch_has_traunt1`
    FOREIGN KEY (`traunted` , `traunted_game_idGame` )
    REFERENCES `mydb`.`vouch_has_traunt` (`vouch_idvouch` , `game_idGame` )
    ON DELETE CASCADE
    ON UPDATE CASCADE)
ENGINE = InnoDB
DEFAULT CHARACTER SET = latin1;



SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;